import babelpolyfill from 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-default/index.css'
//import './assets/theme/theme-green/index.css'
import VueRouter from 'vue-router'
import store from './vuex/store'
import http from "./api/http";
// import Vuex from 'vuex'
//import NProgress from 'nprogress'
//import 'nprogress/nprogress.css'
import routes from './routes'
// import Mock from './mock'
// Mock.bootstrap();
import 'font-awesome/css/font-awesome.min.css'




Vue.use(ElementUI)
Vue.use(VueRouter)
// Vue.use(Vuex)
Vue.prototype.$axios = http;

//NProgress.configure({ showSpinner: false });

const router = new VueRouter({
  routes
})
Vue.filter('twoBit',function (val) {
    if(val){
        return parseFloat(val).toFixed(2)
    }else{
        return '0.00'
    }
})
Vue.filter('division',function (num) {
    if(num){
        return (parseFloat(num)/1000).toFixed(2)
    }else{
        return '0.00'
    }
})
Vue.filter('field',function (num) {
    var fieldTxt = require('./api/fieldTxt.json')
    let fieldList= fieldTxt
    fieldList.forEach((val)=>{
        if(val.value == num){
            fieldTxt = val.label
        }
    })
    return fieldTxt
})
Vue.filter('forArray',function (num) {
    let ArrayTxt = ''
    num.forEach((val)=>{
        ArrayTxt += val + '-'
    })
    ArrayTxt=ArrayTxt.substring(0,ArrayTxt.length-1)
    return ArrayTxt
})

Vue.filter('game',function (txt) {
    let gameTxt = ''
    let gameList=[
        {value: 'ExplodeAsGoldenFlower', label: '炸金花'},
        {value: 'CompetitiveBull', label: '抢庄牛牛'},
        {value: 'BucketPush', label: '推筒子'},
        {value: 'DoublebullHundred', label: '百人牛牛'},
        {value: 'DragonAndTiger', label: '龙虎'},
        {value: 'Baccarat', label: '百家乐'},
        {value: 'CrazyBull', label: '疯狂牛牛'}
    ]
    gameList.forEach((val)=>{
        if(val.value == txt){
            gameTxt = val.label
        }
    })
    return gameTxt
})
Vue.prototype.global = function () {
    const token = sessionStorage.getItem('token');
    return {token}
}
Vue.prototype.Todate1 = function(time, format) { //Fri Oct 31 18:00:00 UTC+0800 2008
    var t = new Date(time);
    var tf = function (i) {
        return (i < 10 ? '0' : '') + i
    }
    return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function (a) {
        switch (a) {
            case 'yyyy':
                return tf(t.getFullYear());
                break;
            case 'MM':
                return tf(t.getMonth() + 1);
                break;
            case 'mm':
                return '00';
                break;
            case 'dd':
                return tf(t.getDate());
                break;
            case 'HH':
                return '00';
                break;
            case 'ss':
                return '00';
                break;
        }
    })
}
Vue.prototype.Todate = function(time, format) { //Fri Oct 31 18:00:00 UTC+0800 2008
    var t = new Date(time);
    var tf = function (i) {
        return (i < 10 ? '0' : '') + i
    }
    return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function (a) {
        switch (a) {
            case 'yyyy':
                return tf(t.getFullYear());
                break;
            case 'MM':
                return tf(t.getMonth() + 1);
                break;
            case 'mm':
                return '59';
                break;
            case 'dd':
                return tf(t.getDate());
                break;
            case 'HH':
                return '23';
                break;
            case 'ss':
                return '59';
                break;
        }
    })
}
Vue.prototype.changeDate = function(datetimes){
    var date = new Date(datetimes);
    let Y = date.getFullYear() + '-';
    let M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
    let D = date.getDate() + ' ';
    var h = date.getHours() + ':';
    var m = date.getMinutes() + ':';
    if (date.getMinutes()<10){
        m = '0'+m
    }
    var s = date.getSeconds();
    if (s<10){
        s = '0'+s
    }
    return Y+M+D+h+m+s;
}
Vue.prototype.changeTime = function(datetimes){
    var date = new Date(datetimes);
    var h = date.getHours() + ':';
    var m = date.getMinutes();
    if (date.getMinutes()<10){
        m = '0'+m
    }
    return h+m;
}
router.beforeEach((to, from, next) => {
  //NProgress.start();
  window.clearInterval(window.timer)
  if (to.path == '/login') {
    sessionStorage.removeItem('user');
  }
  let user = sessionStorage.getItem('user');
  if (!user && to.path != '/login') {
    next({ path: '/login' })
  } else {
      next()
  }
})

//router.afterEach(transition => {
//NProgress.done();
//});

new Vue({
  //el: '#app',
  //template: '<App/>',
  router,
  store,
  //components: { App }
  render: h => h(App)
}).$mount('#app')

